﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.IdentityModel.Tokens;
using Qy.Scenario;
using System.Threading.Tasks;

namespace Qy.Web.Areas.Home.Controllers;

[Area("Home")]
public class ListController : Base
{
    private readonly ContentService _ContentService;
    private readonly ContentCateService _ContentCateService;

    public ListController(ContentService contentService, ContentCateService contentCateService)
    {
        _ContentService = contentService;
        _ContentCateService = contentCateService;
    }

    [HttpGet]
    public async Task<IActionResult> IndexAsync(int id, int page = 1)
    {
        if (id < 1) return View("../Common/404");
        ContentCate cateInfo = await _ContentCateService.GetOneAsync(id);
        if (cateInfo == null) return View("../Common/404");
        ContentQuery contentQuery = new()
        {
            PageSize = cateInfo.Num,
            PageNum = page
        };
        PagedInfo<ViewContentAndCate> infoList = await _ContentService.GetListByCidAsync(id, contentQuery);
        ViewBag.cateInfo = cateInfo;
        return cateInfo.Theme.IsNullOrEmpty() ? View(infoList) : View(cateInfo.Theme, infoList);
    }
}
